package cn.lx.es.query.processor;

import cn.lx.es.query.annotation.ExistsSearch;
import cn.lx.es.query.annotation.SearchProcessor;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.lang.reflect.Field;

/**
 * 内置处理器 - 字段存在查询处理器
 */
@SearchProcessor
public class SearchExistsProcessor implements SearchAnnotationProcessor<ExistsSearch> {
    @Override
    public void process(ExistsSearch annotation, Field field, Object value, BoolQueryBuilder boolQueryBuilder) {
        boolQueryBuilder.must(QueryBuilders.existsQuery(field.getName()));
    }
    @Override
    public Class<ExistsSearch> getAnnotationType() {
        return ExistsSearch.class;
    }
}
